﻿@model QuanLyGiaoVuUI.Models.GiangVienClient.DeTaiGiangVienClientViewModel
<pages validaterequest="false" />
@{
    ViewBag.Title = "DeTai";
    Layout = "~/Views/Shared/_GiangVienClientLayout.cshtml";
}

<script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>

<div id="gv-main-wrapper">
    @{Html.RenderPartial("GiangVienClientGiangDayMenuPartial");}

    <div id="main" class="grid_10 gvclientmain">
        <!--  start page-heading -->

        <div id="page-heading" class="box round first grid">
            <h2>Đăng ký đề Tài Năm Học @Model.namHoc.Nam1 - @Model.namHoc.Nam2</h2>
            <!-- end page-heading -->

            <div id="gvclientmaincontent" class="block"> 
                <div><input type="button" id="btnThemDT" value="Thêm mới"/></div>               
                @*<div>
                    <div>
                        <div>
                            <span style="width: 100px; margin: 10px;">Tên Đề Tài:</span><span><input type="text" id="TenDeTai" style="width: 700px;" /></span>
                        </div>
                        <div style="margin-left: 15px;">Mô Tả:</div>
                        <div>
                            <textarea id="MoTa" name="MoTa" rows="15" cols="80" style="width: 80%; margin-left: 85px;"></textarea>
                        </div>
                        <div>
                            <input type="button" id="ThemDeTai" value="Thêm" style="width: 100px; padding: 5px; float: right; margin-right: 200px; margin-bottom: 30px;" /></div>
                    </div>
                </div>*@
                <style>
                    .chitietdetai td {
                        padding: 10px;
                    }
                </style>
                <div>
                    <table class="data display datatable">
                        <tr>
                            <th class="sorting">STT</th>
                            <th class="sorting">Tên Đề Tài</th>
                            @*<th class="sorting">Khóa Luận TN</th>*@
                            <th class="sorting">Mô Tả</th>
                            <th class="sorting">Trạng thái</th>
                            <th class="sorting">Lựa Chọn</th>
                        </tr>
                        @{var count = 0; var stt = 1;}
                        @foreach (var detai in Model.deTaiGiangVien)
                        {
                            <tr class="gradeA @(++count % 2 == 0 ? "even" : "odd")">
                                <td class="odd gradeX">@(stt++)</td>
                                <td class="odd gradeX">@detai.TenDeTai</td>
@*                                @if (detai.KhoaLuanTotNghiep > 0)
                                {
                                    <td class="odd gradeX">Có</td>   
                                }
                                else
                                {
                                    <td class="odd gradeX">Không</td>
                                }*@
                                <td class="odd gradeX">@Html.Raw(detai.MoTa)</td>
                                <td class="odd gradeX">@(detai.DatYeuCau==true?"Đã duyệt":"Chờ duyệt")</td>
                                <td class="odd gradeX">
                                    <a class="suadt" rel="@detai.MaDeTai">Sửa</a> | 
                                    <a class="xoadt" rel="@detai.MaDeTai">Xoá</a>
                                </td>                                
                            </tr>
                        }
                    </table>
                </div>
            </div>
        </div>
    </div>

    <div class="clear">&nbsp;</div>

</div>
<div id="suaDeTaiDialog"></div>

@*<script type="text/javascript">
    var editor = CKEDITOR.replace('MoTa');
</script>*@


<script>
    $(document).ready(function () {
        $('#ThemDeTai').click(function () {
            var TenDeTai = $("#TenDeTai").val();
            //var MoTa = $('#MoTa').val();
            var MoTa = editor.getData();
            //alert(TenDeTai + "MoTa:" + MoTa);
            if (TenDeTai.trim().length < 1 || MoTa.trim().length < 1) {
                ToastManager.showStickyWarningToast("Tên đề tài và mô tả không được rỗng!");
                return;
            }
            else {
                $.post("/GiangVienClient/DeTai", { TenDeTai: TenDeTai, MoTa: MoTa }, function (data) {
                    alert(data.message);
                    if (data.success == true) {
                        window.location = "/GiangVienClient/DeTai";
                    }
                });
            }
        });
        $('#btnThemDT').click(function () {
            var madetai = "none";
            $("#suaDeTaiDialog").load('/GiangVienClient/CapNhatDeTai/' + madetai);
            $("#suaDeTaiDialog").dialog("open");
        });
        $('.xoadt').click(function () {
            var r=confirm("Bạn có muốn xoá đề tài này?")
            if (r==false)
            {
                return;
            }    
            var madetai = $(this).attr("rel");
            //alert(madetai);
            if (madetai == null || madetai == "") {
                return;
            }
            else {
                //alert(madetai);
                $.post("/GiangVienClient/XoaDeTai", { MaDeTai: madetai }, function (data) {
                    if (data.success == true) {
                        ThongBao(data);
                        setTimeout('reloadPage()', 2000);                        
                    }
                    else {
                        ThongBao(data);
                    }
                });
            }
        });
    });
    $("#suaDeTaiDialog").dialog({
        autoOpen: false, modal: true, width: 800, height: "auto", title: "Sửa đề tài"
    });
    $('.suadt').click(function () {
        var madetai = $(this).attr("rel");
        $("#suaDeTaiDialog").load('/GiangVienClient/CapNhatDeTai/' + madetai);
        $("#suaDeTaiDialog").dialog("open");
    });
    function reloadPage() {
        window.location = "/GiangVienClient/Detai";
    }
    function ThongBao(data) {
        if (data.success) {
            ToastManager.showSuccessToast(data.message);
            setTimeout(function () {
                reloadPage();
            }, 2000);
        }
        else {
            ToastManager.showStickyWarningToast(data.message);
        }
    }
</script>
